package cn.sf.sufingadminprovider.serviceImpl;

import cn.sf.pojo.Admin;
import cn.sf.service.FoulService;
import cn.sf.sufingadminprovider.dao.FoulMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class FoulServiceImpl implements FoulService {

  @Resource private FoulMapper foulMapper;

  @Override
  @RequestMapping("/selectAllFoulInfo")
  public List<Admin> selectAllFoulInfo() {
    System.out.println("查询封禁名单");
    return foulMapper.selectAllFoulInfo();
  }

  @Override
  @RequestMapping("/selectFoulById")
  public List<Admin> selectFoulById(@RequestParam("adminId") long adminId) {
    System.out.println("依据adminId查询名单");

    return foulMapper.selectFoulById(adminId);
  }

  @Override
  @RequestMapping("/selectFoulByType")
  public List<Admin> selectFoulByType(@RequestParam("foulType") String foulType) {

    return foulMapper.selectFoulByType(foulType);
  }

  @Override
  @RequestMapping("/insertFoulInfo")
  public int insertFoulInfo(@RequestBody Admin admin) {
    int result = foulMapper.insertFoulInfo(admin);
    if (result > 0) {
      return 1;
    } else {
      return 0;
    }
  }

  @Override
  @RequestMapping("/updateFoulInfo")
  public int updateFoulInfo(@RequestBody Admin admin) {
    int result = foulMapper.updateFoulInfo(admin);
    if (result > 0) {
      return 1;
    } else {
      return 0;
    }
  }

  @Override
  @RequestMapping("/deleteFoulInfo")
  public int deleteFoulInfo(@RequestParam("adminUserId") long adminUserId) {
    int result = foulMapper.deleteFoulInfo(adminUserId);
    if (result > 0) {
      return 1;
    } else {
      return 0;
    }
  }
}
